var rewire = require("rewire")
const wdio = rewire('webdriverio')
const { enterUserInfoPage, enterFirstTopic, followTopicFansAndComment, followBigVTask } = rewire('./appiumInstagram.cjs')


const opts = {
    path: '/wd/hub',
    port: 4723,
    capabilities: {
        "platformName": "Android",
        "platformVersion": "6.0.1",
        "deviceName": "xiaomi",
        "app": "e:/Instagram_v208.0.0.32.135_apkpure.com.apk",
        "appPackage": "com.instagram.android",
        "appActivity": "com.instagram.mainactivity.MainActivity",
        "automationName": "UiAutomator2",
        "newCommandTimeout": 3600,
        "noReset": true
    }
}

let client = null
async function main () {
    client = await wdio.remote(opts)
    console.log(client)
}

main()


const uidList = ['miamaples', 'eleonore', 'betsa', 'sissi', 'chani', 'soph']



function makeExecutor(plan, getData, doItem) {
    return async () => {
        const data = await getData()
        for (let item of data) {
            await plan(async () => { await doItem(item) })
        }
    }
}


function makeIntervalPlan (ms) {
    return async function(f) {
        await f()
        await sleep(ms)
    }
}


function sleep(ms) {
    return new Promise((resolve) => {setTimeout(resolve, ms)})
}


// 每隔一段时间执行一个元素
const executor = makeExecutor(
    makeIntervalPlan(60*10*1000),
    async () => {
        return uidList
    },
    async (item) => {
        await followBigVTask(client, item)
    }
)


executor()
